from PySide6.QtWidgets import QWidget
from basicwidget.toolbar.floating_toolbar import FloatingToolbar
from basicwidget.dockwidget.custom_dockwidget import CustomDockWidget
from basicwidget.button.custom_toolbutton import CustomToolButton
from basicwidget.button.custom_pushbutton import CustomPushButton
from basicwidget.tab.custom_tabwidget import CustomTabWidget

class WidgetFactory:
    """
    部件工厂类
    负责创建各种自定义组件
    """
    
    @staticmethod
    def create_toolbar(title, parent=None):
        """创建浮动工具栏"""
        return FloatingToolbar(parent)
    
    @staticmethod
    def create_dockwidget(title, widget=None, parent=None):
        """创建停靠窗口"""
        dock = CustomDockWidget(title, parent)
        if widget:
            dock.setWidget(widget)
        return dock
        
    @staticmethod
    def create_toolbutton(text="", icon=None, parent=None):
        """创建工具栏按钮"""
        return CustomToolButton(text, icon, parent)
    
    @staticmethod
    def create_pushbutton(text="", icon=None, parent=None, style=None):
        """
        创建普通按钮
        参数:
            text: 按钮文本
            icon: 按钮图标
            parent: 父部件
            style: 按钮样式，可选值: "primary", "secondary", "danger", "success"
        """
        button = CustomPushButton(text, icon, parent)
        
        if style:
            if style == "primary":
                button.setPrimaryStyle()
            elif style == "secondary":
                button.setSecondaryStyle()
            elif style == "danger":
                button.setDangerStyle()
            elif style == "success":
                button.setSuccessStyle()
                
        return button
    
    @staticmethod
    def create_tabwidget(parent=None):
        """创建标签页控件，替代传统菜单栏"""
        return CustomTabWidget(parent)
    
    @staticmethod
    def create_content_widget(content_type, parent=None, **kwargs):
        """
        创建内容部件
        参数:
            content_type: 内容类型，如"editor", "browser", "viewer"等
            parent: 父部件
            kwargs: 其他参数
        """
        if content_type == "editor":
            # 示例：创建一个编辑器部件
            return QWidget(parent)  # 这里只是一个占位符
        elif content_type == "browser":
            # 示例：创建一个浏览器部件
            return QWidget(parent)  # 这里只是一个占位符
        else:
            # 默认返回一个空的QWidget
            return QWidget(parent) 